//引入koa框架
const Koa = require('koa')
const userRouter = require('./src/api/user')
const studentRouter = require('./src/api/student')
const managerRouter = require('./src/api/manager')
const dataRouter = require('./src/api/data')
const bodyParser = require('koa-bodyparser')
const cors = require('koa2-cors');
//创建服务器
const app = new Koa();

// app.use(cors());
app.use(bodyParser())
app.use(async (ctx, next) => {
    ctx.set('Access-Control-Allow-Origin', '*');
    ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With ,Origin, Accept');
    ctx.set('Access-Control-Allow-Methods', ' POST, GET,  OPTIONS');
    if (ctx.method == 'OPTIONS') {
        ctx.body = 200;
    } else {
        await next();
    }
})

app.use(userRouter.routes());
app.use(studentRouter.routes());
app.use(managerRouter.routes());
app.use(dataRouter.routes());


//监听端口

app.listen(979)